/*
 * @Author: Jiraiya
 * @Date: 2020-05-07 17:30:45
 * @LastEditors: Jiraiya
 * @LastEditTime: 2020-05-09 14:33:41
 * @Description: 
 */
const numeral = require('numeral')
const colors = ['#000', 'red', 'blue', 'green']

const getBarOptions = function (x, y) {
    return {
        title: {
            text: '基金浮动对比'
        },
        legend: {
            data: ['bar', 'bar1']
        },
        toolbox: {
            // y: 'bottom',
            feature: {
                magicType: {
                    type: ['stack', 'tiled']
                },
                dataView: {},
                saveAsImage: {
                    pixelRatio: 2
                }
            }
        },
        tooltip: {},
        xAxis: {
            data: x,
            splitLine: {
                show: false
            }
        },
        yAxis: {},
        series: [
            {
                name: 'bar',
                type: 'bar',
                data: y,
            },
            {
                name: 'bar1',
                type: 'bar',
                data: y.reverse()
            }
        ],
    }
}

function ratio({title, yearList, data}){
    
    return {
        title: {
            text: title,
            left: 'center'
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'cross'
            },
            formatter: function(params){
                const [s1, s2] = params.map(e => {
                    return numeral(e.data).format('0,000.00');
                })
                if(s2){
                    return `本息和：${s1}元</br>本金和：${s2}元`;
                }
                return `收益率：${s1}%`;
            }
        },
        xAxis: {
            name: '年',
            data: yearList,
            splitLine: {
                show: true
            }
        },
        yAxis: {
            name: '元',
            type: 'value',
            splitLine: {
                lineStyle: {
                    type: 'dashed'
                }
            }
        },
        series: data.map((e, idx) => {
            return {
                name: 'line',
                type: 'line',
                data: e,
                lineStyle: {
                    color: colors[idx]
                }
            }
        })
    }
}

export {
    getBarOptions,
    ratio,
}